package com.huawei.hianalytics.f.f;

import android.content.Context;
import android.text.TextUtils;
import com.huawei.hianalytics.f.b.a;
import com.huawei.hianalytics.f.b.c;
import com.huawei.hianalytics.f.b.e;
import com.huawei.hianalytics.f.g.h;
import com.huawei.hianalytics.f.g.j;
import com.huawei.hianalytics.g.b;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public final class f implements h {
    private Context a;
    private String b;
    private String c;
    private int d = -1;
    private String e;

    public f(Context context, String str, String str2, String str3) {
        this.a = context;
        this.b = str;
        this.c = str2;
        this.e = str3;
    }

    private void a(String str, List<c> list) {
        if (list != null && list.size() > 0) {
            String str2 = str;
            new c(this.a, str2, (c[]) list.toArray(new c[list.size()]), this.e, "").a();
        }
    }

    public void run() {
        boolean z = true;
        b.b("HiAnalytics/event", "run report.TAG : %s,TYPE: %s", this.b, this.c);
        String str = this.b;
        boolean b = h.b(this.a);
        if (b) {
            this.d = 1;
            z = b;
        } else if (!(TextUtils.isEmpty(this.c) && TextUtils.isEmpty(this.b))) {
            if (!"_default_config_tag".equals(this.b) && "allType".equals(this.c)) {
                b.c("EventReportTask", "eventType UnKnown,Stop Report!");
                return;
            } else if ("_default_config_tag".equals(this.b) || "allType".equals(this.c)) {
                z = b;
            } else {
                str = str + "-" + this.c;
                z = b;
            }
        }
        Map a = e.a(h.d(this.a, "stat_v2_1"), this.a, str, z);
        Map a2 = a.a(h.d(this.a, "cached_v2_1"), this.a, str, z);
        if (a == null || a2 == null) {
            b.c("EventReportTask", "Unknown anomaly,data error!");
        } else if (a.size() == 0 && a2.size() == 0) {
            b.c("EventReportTask", "Unknown anomaly,No data send!");
        } else {
            j.b(a, a2);
            if (z) {
                q.a().a(a2, this.e);
                for (String a3 : com.huawei.hianalytics.a.b.a()) {
                    q.a().a(a3);
                }
            } else {
                a = (Map) a2.get(str);
                if (a != null) {
                    for (Entry value : a.entrySet()) {
                        a(str, (List) value.getValue());
                    }
                }
            }
            h.a(str, z, this.a);
            com.huawei.hianalytics.f.g.a.a(this.a).a(com.huawei.hianalytics.f.g.f.a(), this.d);
        }
    }
}
